/************************************************************
wx
2020/2/2

*************************************************************/

using System.Collections.Generic;
using AutoJsonClass;
using Fight;
using UnityEngine;

public class Monster : Character
{
    public static Monster GenerateMonster(int id)
    {
        Monster monster = new Monster();
        MonsterConfig config = ConfigManager.Instance.GetMonsterConfig(id);
        if (config == null)
        {
            return null;
        }

        monster.Attack = config.Atk;
        monster.Defend = config.Def;
        monster.Hp = config.Hp;
        monster.HpMax = config.HpMax;
        monster.Mp = config.Mp;
        monster.MpMax = config.MpMax;
        monster.Level = config.Level;
        monster.Name = config.Name;
        monster.Type = CharacterType.Monster;
        return monster;
    }

    private Monster()
    {
        ListCards = new List<Card>();
    }

    public override bool UseCard(Character enmery)
    {
        if (ListCards == null || ListCards.Count == 0)
        {
            return false;
        }
        
        Timer.Register(TimerId.MonsterUseCard, 0.8f, () =>
        {
            if (ListCards.Count == 0)
            {
                Timer.Cancel(TimerId.MonsterUseCard);
                FightManager.Instance.NextRound();
                return;
            }

            int index = Random.Range(0, ListCards.Count - 1);
            SelectedCard = ListCards[index];
            bool bUse = base.UseCard(enmery);
            if (!bUse || ListCards.Count == 0)
            {
                Timer.Cancel(TimerId.MonsterUseCard);
                FightManager.Instance.NextRound();
            }
        }, null, true);

        return true;
    }
}
